from selenium.webdriver.common.by import By
from base.base_page import BasePage,BaseHandle
# 1对象库层
class LoginPage(BasePage):
    def __init__(self):
        super().__init__()    # 初始化 driver
        # 定义元素定位方式
        self.username=By.ID,"username"
        self.password = By.ID, "password"
        self.code = By.ID, "verify_code"
        self.login_btn=By.CSS_SELECTOR,".J-login-submit"

    # 获取元素的方法
    def find_username(self):
        return self.get_element(self.username)

    def find_password(self):
        return self.get_element(self.password)

    def find_code(self):
        return self.get_element(self.code)

    def find_login(self):
        return self.get_element(self.login_btn)


# 2操作层
class LoginHandle(BaseHandle):
    def __init__(self):
        self.login_page=LoginPage()    # 实例化对象库层

    # 封装操作
    def input_username(self,username):
        self.input_text(self.login_page.find_username(),username)

    def input_password(self,password):
        self.input_text(self.login_page.find_password(),password)

    def input_code(self,code):
        self.input_text(self.login_page.find_code(),code)

    def click_login(self):
        self.login_page.find_login().click()

# 3业务层
class LoginProxy:
    def __init__(self):
        self.login_handle=LoginHandle()    # 实例化操作层

    def login(self,username,password,code):
        self.login_handle.input_username(username)
        self.login_handle.input_password(password)
        self.login_handle.input_code(code)
        self.login_handle.click_login()

